<?php

class Post_model extends CI_Model
{

    public function getPosts()
    {
        $this->db
                ->select('A.id, A.content, A.time, A.type')
                ->from('posts A')
                ->order_by('A.time', 'DESC');

        $query = $this->db->get();
        $rt    = array();

        if ($query->num_rows() > 0) {

            $rt = $query->result_array();
        }

        $query->free_result();
        return $rt;
    }

    public function editPosts($array, $cond)
    {
        return $this->db->where($cond)
                        ->update('posts', $array);
    }

    public function addPost($array)
    {
        return $this->db->insert('posts', $array);
    }
    
    public function delPost($id) {
        
        return $this->db->delete('posts', array(
            'id'    =>  $id
        ));
    }

}
